package org.grayrabbit.cms.entity;

// Generated 2011-5-16 13:39:30 by Hibernate Tools 3.3.0.GA

import java.util.Collection;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.DiscriminatorColumn;
import javax.persistence.DiscriminatorType;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Transient;

import org.grayrabbit.cms.security.PermissionChecker;
import org.grayrabbit.cms.security.SecurityUser;
import org.grayrabbit.cms.util.AESEncipher;
import org.hibernate.annotations.GenericGenerator;


/**
 * UcUser generated by hbm2java
 */
@Entity
@Inheritance(strategy=InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(
    name="User_Type",
    discriminatorType=DiscriminatorType.STRING
)
@Table(name = "UC_USER")
public class User implements SecurityUser,java.io.Serializable {

	private static final long serialVersionUID = -6952998430362817177L;
	private String userId;
	//private AppMsgGroup appMsgGroup;
	private String userLoginName;
	private String userRealName;
	private String userPapersType;
	private String userPapersNum;
	private String userPassword;
	private String userPhone;
	private String userAddress;
	private String userIntroduction;
	private Date createTime;
	private Date userLoginTime;
	private String email;
	private Boolean male;

	private String mobile;
	private String blacklist;
	private String postNum;
	
	private Boolean isEnabled;//是否启用
	private String loginIp;
	
	//end
	
	
	@Override
	public boolean equals(Object o){
		
		if(this == o){
			return true;
		}
		if(o==null){
			return false;
		}
		if( !(o instanceof User))
		   return false;
		User u =(User)o;
		if(u.getUserId()==this.userId){
			return true;
		}else{
			return false;
		}
	}

	public User() {
	}

	public User(String userId) {
		this.userId = userId;
	}

	@Id
	@Column(name = "USER_ID", unique = true, nullable = false, length = 32)
	@GeneratedValue(generator = "paymentableGenerator")       
	@GenericGenerator(name = "paymentableGenerator", strategy = "uuid") 
	public String getUserId() {
		return this.userId;
	}

	public void setUserId(String userId) {
		this.userId = userId;
	}

	@Column(name = "USER_LOGIN_NAME", length = 64)
	public String getUserLoginName() {
		return this.userLoginName;
	}

	public void setUserLoginName(String userLoginName) {
		this.userLoginName = userLoginName;
	}

	@Column(name = "USER_REAL_NAME", length = 64)
	public String getUserRealName() {
		return this.userRealName;
	}

	public void setUserRealName(String userRealName) {
		this.userRealName = userRealName;
	}

	@Column(name = "USER_PAPERS_TYPE", length = 32)
	public String getUserPapersType() {
		return this.userPapersType;
	}

	public void setUserPapersType(String userPapersType) {
		this.userPapersType = userPapersType;
	}

	@Column(name = "USER_PAPERS_NUM", length = 64)
	public String getMiUserPapersNum() {
		return this.userPapersNum;
	}

	public void setMiUserPapersNum(String userPapersNum) {
		this.userPapersNum = userPapersNum;
	}
	
	@Transient
	public String getUserPapersNum() {
		return AESEncipher.getInstance().arDecrypt(this.userPapersNum);
	}

	public void setUserPapersNum(String userPapersNum) {
		this.userPapersNum = AESEncipher.getInstance().arEncrypt(userPapersNum);
	}

	@Column(name = "USER_PASSWORD", length = 64)
	public String getUserPassword() {
		return this.userPassword;
	}

	public void setUserPassword(String userPassword) {
		this.userPassword = userPassword;
	}

	@Column(name = "USER_PHONE", length = 16)
	public String getMiUserPhone() {
		return this.userPhone;
	}

	public void setMiUserPhone(String userPhone) {
		this.userPhone = userPhone;
	}
	
	@Transient
	public String getUserPhone() {
		return AESEncipher.getInstance().arDecrypt(this.getMiUserPhone());
	}
	
	public void setUserPhone(String userPhone) {
		this.userPhone = AESEncipher.getInstance().arEncrypt(userPhone);
	}

	@Column(name = "USER_ADDRESS", length = 64)
	public String getUserAddress() {
		return this.userAddress;
	}

	public void setUserAddress(String userAddress) {
		this.userAddress = userAddress;
	}

	@Column(name = "USER_INTRODUCTION", length = 512)
	public String getUserIntroduction() {
		return this.userIntroduction;
	}

	public void setUserIntroduction(String userIntroduction) {
		this.userIntroduction = userIntroduction;
	}

	@Temporal(TemporalType.TIMESTAMP)
	@Column(name = "CREATE_TIME", length = 7)
	public Date getCreateTime() {
		return this.createTime;
	}

	public void setCreateTime(Date createTime) {
		this.createTime = createTime;
	}

	@Column(name = "EMAIL", length = 256)
	public String getEmail() {
		return this.email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	@Column(name = "MALE", precision = 1, scale = 0)
	public Boolean getMale() {
		return this.male;
	}

	public void setMale(Boolean male) {
		this.male = male;
	}


	@Column(name = "MOBILE", length = 16)
	public String getMiMobile() {
		return mobile;
	}

	public void setMiMobile(String mobile) {
		this.mobile = mobile;
	}

	/**
	 * 密文处理
	 * @return
	 */
	@Transient
	public String getMobile() {
			return AESEncipher.getInstance().arDecrypt(getMiMobile());
	}

	public void setMobile(String miMobile) {
		this.mobile = AESEncipher.getInstance().arEncrypt(miMobile);
	}
	
	
	@Column(name = "POSTNUM", length = 16)
	public String getPostNum() {
		return postNum;
	}

	public void setPostNum(String postNum) {
		this.postNum = postNum;
	}

	@Column(name = "BLACK_LIST", length = 4000)
	public String getBlacklist() {
		return blacklist;
	}

	public void setBlacklist(String blacklist) {
		this.blacklist = blacklist;
	}

	@Transient
	public String getUserType(){
		return PermissionChecker.USER_TYPE_USER;
	}

	private Collection<String> perssmins;
	
	@Transient
	public Collection<String> getPerssmins() {
		return perssmins;
	}

	public void setPerssmins(Collection<String> perssmins) {
		this.perssmins = perssmins;
	}
	
	@Transient
	public Object getUser() {
		return this;
	}

	@Transient
	public String getUserName() {
		return this.userLoginName;
	}

	@Temporal(TemporalType.TIMESTAMP)
	@Column(name = "USER_LOGIN_TIME", length = 7)
	public Date getUserLoginTime() {
		return userLoginTime;
	}

	public void setUserLoginTime(Date userLoginTime) {
		this.userLoginTime = userLoginTime;
	}


	@Column(name="IS_ENABLED",precision = 1, scale = 0)
	public Boolean getIsEnabled() {
		return isEnabled;
	}

	public void setIsEnabled(Boolean isEnabled) {
		this.isEnabled = isEnabled;
	}

	@Column(name="USER_LOGIN_IP", length=32)
	public String getLoginIp() {
		return loginIp;
	}

	public void setLoginIp(String loginIp) {
		this.loginIp = loginIp;
	}

	
	
}
